import {
  nameCheckApi,
  registerApi,
  loginApi,
  getUserApi,
  userLogoutApi
} from 'src/api/user'
import { __setUser } from 'common/js/user'
import { User } from 'classes/user'

export const nameCheck = (username) => {
  return nameCheckApi(username)
}

export const doRegister = (user) => {
  return registerApi(user)
}

export const doLogin = (username, password) => {
  return loginApi(username, password)
}

export const getUser = () => {
  return getUserApi().then(data => {
    __setUser(data)
  })
}

export const userLogout = () => {
  return userLogoutApi().then(() => {
    __setUser(new User())
  })
}
